<?
    class Principio_Model_Type extends Principio_Model_Templatable implements PrincipioLab_IDAble
    {
        use PrincipioLab_TCollection;

        private $id;
        private $tftp_filename;
        private $caption;
        private $exts;
        private $model_firmware;
        private $use_default_TFTP_config;
        private $TFTP_config;
        private $vendor_id; // Not Used
        private $add_extra_TFTP_config;
        private $extra_TFTP_config;
        private $use_common_template;
        private $firmware_id;


        public function __construct($values)
        {
            parent::__construct();

            $this->vendor_id = -1;

            if (is_int($values))
            {
                $this->id = -1;
                $this->firmware_id = -1;
                $this->caption = "";
                $this->model_firmware = null;
                $this->exts = intval($values);
                $this->use_default_TFTP_config = 1;
                $this->TFTP_config = "";
                $this->tftp_filename = "";
                $this->add_extra_TFTP_config = 0;
                $this->extra_TFTP_config = "";
                $this->use_common_template = true;

                $this->initTemplates($this->exts);
            }
            elseif (is_array($values))
            {
                $this->id = intval($values['id']);
                $this->caption = $values['caption'];
                $this->tftp_filename = $values['tftp_filename'];
                $this->exts = intval($values['exts']);
                $this->use_default_TFTP_config = intval($values['use_default_tftp_config']);
                $this->TFTP_config = ($this->use_default_TFTP_config == 0) ? $values['tftp_config'] : "";
                $this->model_firmware = null;
                $this->firmware_id = $values['firmware_id'];
                $this->add_extra_TFTP_config = $values['add_extra_tftp_config'];
                $this->extra_TFTP_config = $values['extra_tftp_config'];
                $this->use_common_template = (intval($values['use_common_template']) == 1);

                $this->initTemplates();
            }
            else
                throw new RuntimeException("Wrong parameter [values].");
        }


        public function _getID() { return $this->id; }


        public static function fromArray(array $values = null)
        {
            return new Principio_Model_Type($values);
        }


        public function getID() { return $this->id; }
        public function getTFTPFilename() { return $this->tftp_filename; }
        public function getCaption() { return $this->caption; }
        public function getExts() { return $this->exts; }
        public function getUseDefaultTFTPConfig() { return $this->use_default_TFTP_config; }
        public function getAddExtraTFTPConfig() { return $this->add_extra_TFTP_config; }
        public function getExtraTFTPConfig() { return $this->extra_TFTP_config; }
        public function getUseCommonTemplate() { return $this->use_common_template; }


        public function getModelFirmware()
        {
            if (is_null($this->model_firmware))
                $this->model_firmware = Principio_Model_FirmwareMapper::get($this->firmware_id);

            return $this->model_firmware;
        }


        public function getTFTPConfig()
        {
            return ($this->getUseDefaultTFTPConfig() == 0)
                ? $this->TFTP_config
                : Principio_Model_SettingMapper::fetch(Principio_Model_SettingMapper::SETTING_TFTP_DEFAULT_CONFIG)->getValue();
        }


        public function getFullTFTPConfig()
        {
            return  "<flat-profile>\n".
                    "<Profile_Rule>".Principio_Model_SettingMapper::getProfileRuleHTTP()->getValue()."</Profile_Rule>\n".
                    $this->getTFTPConfig()."\n".
                    ($this->getAddExtraTFTPConfig() ? $this->getExtraTFTPConfig()."\n" : "").
                    "</flat-profile>";
        }


        public function setTFTPFilename($tftp_filename)
        {
            $this->tftp_filename = $tftp_filename;
            return $this;
        }


        public function setCaption($caption)
        {
            $this->caption = $caption;
            return $this;
        }


        public function setModelFirmware(Principio_Model_Firmware $model_firmware)
        {
            $this->model_firmware = $model_firmware;
            return $this;
        }


        public function setUseDefaultTFTPConfig($use_default_TFTP_config)
        {
            $this->use_default_TFTP_config = $use_default_TFTP_config;
            return $this;
        }


        public function setTFTPConfig($TFTP_config)
        {
            $this->setUseDefaultTFTPConfig(0);
            $this->TFTP_config = $TFTP_config;
            return $this;
        }


        public function setDefaultTFTPConfig()
        {
            $this->setUseDefaultTFTPConfig(1);
            $this->TFTP_config = "";
            return $this;
        }


        public function setAddExtraTFTPConfig($add_extra_TFTP_config)
        {
            $this->add_extra_TFTP_config = $add_extra_TFTP_config;
            return $this;
        }


        public function setExtraTFTPConfig($extra_TFTP_config)
        {
            $this->extra_TFTP_config = $extra_TFTP_config;
            return $this;
        }


        public function setID($id)
        {
            $this->id = intval($id);
            return $this;
        }



        protected function fetchTemplates() { return Principio_Model_TypeExtTemplateMapper::fetch($this); }
        public function addTemplates() { return Principio_Model_TypeExtTemplateMapper::insert($this); }
        public function saveTemplates() { return Principio_Model_TypeExtTemplateMapper::update($this); }
        public function deleteTemplates() { return Principio_Model_TypeExtTemplateMapper::delete($this); }


        public function add() { return Principio_Model_TypeMapper::save($this); }
        public function save() { return Principio_Model_TypeMapper::save($this); }
        public function delete() { return Principio_Model_TypeMapper::delete($this); }
    }
?>